package com.dao;

import java.sql.SQLException;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import com.pojo.User;
import com.utils.JDBCDBCPUtils;

public class UserDao {
	
	QueryRunner qr=new QueryRunner(JDBCDBCPUtils.getDataSource());

	public User login(String username,String password){
		String sql="select *from user where username=? and password=?";
		User user =null;
		try {
			 user = qr.query(sql, new BeanHandler<User>(User.class),username,password);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return user;
	}

	public User findByUsername(String username) {
		String sql="select *from user where username=? ";
		User user =null;
		try {
			 user = qr.query(sql, new BeanHandler<User>(User.class),username);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return user;
	}
}
